<template>
    <li @click.stop="selectOptionClick" 
        @mouseenter.stop=""
        :class="{'selected': itemSelected}"
        class="bc-select-dropdown__item">
        <span>{{currentLabel}}</span>
    </li>
</template>

<script>
import bus from './bus.js'
export default {
    name: 'BcOption',
    inject: ['select'],
    props: {
        value: {
            required: true
        },
        label: [String, Number],
        disabled: {
            type: Boolean,
            default: false
        }
    },
    computed: {
        isObject() {
            return Object.prototype.toString.call(this.value).toLowerCase() === '[object object]';
        },
        currentLabel() {
            return this.label || (this.isObject?'':this.value);
        },
        itemSelected() {
            return this.select.value == this.value;
        }
    },
    methods: {
        selectOptionClick() {
            let selected = [{value: this.value,label: this.label}, false];
            bus.$emit('handleOptionClick', selected);
        }
    }
}
</script>

<style scoped>
.bc-select-dropdown__item {
    padding: 0 20px;
    height: 34px;
    line-height: 34px;
    font-size: 14px;
    box-sizing: border-box;
    cursor: pointer;
}
.bc-select-dropdown__item.selected {
    color: #2d8cf0;
    font-weight: 600;
    background-color: #f5f7fa;
}
.bc-select-dropdown__item.hover, .bc-select-dropdown__item:hover {
    background-color: #f5f7fa;
}
</style>